package com.qq.googleplay.ui.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qq.googleplay.base.BaseApplication;

/**
 * ============================================================
 * 版 权 ： Google互联网有限公司版权所有 (c) 2016
 * 作 者 : 陈冠杰
 * 版 本 ： 1.0
 * 创建日期 ：2016/3/20 21:32
 * 描 述 ：
 * 修订历史 ：
 * ============================================================
 **/
public class HomeAdapter extends PagerAdapter {

    private String[] mTitle;

    public HomeAdapter(String[] title) {
        mTitle = title;
    }

    @Override
    public int getCount() {

        if (mTitle != null) {
            return mTitle.length;
        }
        return 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        TextView textView = new TextView(BaseApplication.getContext());
        textView.setText(mTitle[position]);
        container.addView(textView);
        return textView;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitle[position];
    }
}
